<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>库存查询</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	     <!-- 页面  -->
	    <section class="AllContent" style="background-color: #fff;padding-bottom:0px;">
	    	<div id="stocklist">
	    		<img style="width: 40%;margin:20px auto;display: block;" src="images/loading5.gif">
	    	</div>
	    </section>
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript">
	    mui.init();
		$('.AllHeader li:eq(1)').text('库存查询');
		$('.AllHeader li:eq(2)').html('<img style="width:25px" src="images/Search.png">')
		
		//扫描器
		document.getElementById('Scanner').addEventListener('tap', function() {
		  var hrefde = $('.ProductsDetails').find('input').val();
		  mui.openWindow({
		    url: hrefde
		  });
		});
		
		$(function (){
            $.ajax({//一个Ajax过程
                type: "post", //以post方式与后台沟通
                url: getServerUrl() + "/Open/ComStat/stocklist",
                dataType: 'json', //从php返回的值以 JSON方式 解释
                data: 'access_token='+getToken(),
                success: function (json) {//如果调用php成功
                    if (json.result == "1") {
                        var html = "";
                        if(!empty(json.productlist)) {
                            for (var i = 0; i < json.productlist.length; i++) {
                                html = html + '<div class="ProductsListContent">';
				            	html = html + '<div class="ProductsDetails" style="margin-top:2px;background-image: url(images/RetreatRight.png)">';
				    			html = html + '<ul>';
				    			html = html + '<li><img width="100%" src='+json.productlist[i].pic_url+'></li>';
						    	html = html + '<li>';
						    	html = html + '<p>'+json.productlist[i].name+'</p>';
						    	html = html + '<p>库存:'+json.productlist[i].qty+'</p>';
						    	html = html + '<p><a class="herfde">查看网点库存</a></p>';
						    	html = html + '<p style="display:none"><input type="text" value="stock_query.html?pid='+json.productlist[i].pid+'" /></p>';
						    	html = html + '</li>';
				    			html = html + '</ul>';
				    			html = html + '</div>';
				    			html = html + '</div>';
                            }
                        }
                        $('.AllContent').css({backgroundColor:'#f3f3f3'});
                        $("#stocklist").html(html);
                        
                        var plchimg = $('.ProductsDetails img').width();
						$('.ProductsDetails img').height(plchimg);
                        
                    	//切换按钮，获取第一个数据的pid
				        $('.ProductsDetails').on('click',function(){
				        	var hrefde = $(this).find('input').val();
				        	
				        	if(hrefde != ''){
				        		mui.openWindow({
									 url: hrefde
								});
				        	}else{
				        		alert('数据正在获取中....')
				        	}
				        });
				        
                    } else {
                        alertMessage("查询数据异常:[" + json.error_description + "]");
                    }
                }
            });
        });
        
        
        
        function onDeviceReady() {
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
        function onBackKeyDown() {
            openUrl("index.html");
        }
	</script>
</html>
